﻿$(document).ready(function() {
    $.ajax({
        url: "/api/DistinctApi/GetAllProvinceInfo",
        type: "GET",
        success: function (data) {
            //alert(JSON.stringify(data.result));
            var departCity = $("#departCity");
            var arriveCity = $("#arriveCity");

            $("#departCity option").remove();
            $("#arriveCity option").remove();

            departCity.append("<option value='-1'>选择起始地</option>");
            arriveCity.append("<option value='-1'>选择目的地</option>");

            $.each(JSON.parse(data).result, function (key, value) {
                var opt = $("<option></option>").text(value).val(key);
                var opt2 = $("<option></option>").text(value).val(key);
                departCity.append(opt);
                arriveCity.append(opt2);
            });
        }

    });

    $("span[id='querytype'] a").click(function () {
        $("span[id='querytype'] a").each(function () {
            $(this).attr("class", "last")
        });
        $(this).attr("class", "on");
        $("#searchType").val($(this).attr("rel"));
    });

    $("#btnSearch").click(function () {
        if ($("#departCity").val() == "-1" || $("#arriveCity").val() == "-1") {
            alert("请选择起始地和目的地");
            return
        }
        if ($("#searchType").val() == "vipline") {
            location.href = "/Freight/vipline?start_area=" + $("#departCity").val() + "&end_area=" + $("#arriveCity").val();
            parent.location.href = "/Freight/vipline?start_area=" + $("#departCity").val() + "&end_area=" + $("#arriveCity").val();
        } else {
            location.href = "/Freight/zhengche?start_area=" + $("#departCity").val() + "&end_area=" + $("#arriveCity").val();
            parent.location.href = "/Freight/zhengche?start_area=" + $("#departCity").val() + "&end_area=" + $("#arriveCity").val();
        }
    });
});

//$('#cc').combotree({
//    url: "areaTree.ajax?areaId=0",
//    onBeforeExpand: function (node) {
//        $('#cc').combotree("tree").tree("options").url = "areaTree.ajax?areaId=" + node.id;
//    }
//});
//$("#departCity").combotree({
//    url: "/api/DistinctApi/GetAllProvinceInfo"
//});